#include "windowStuff.h"

LRESULT CALLBACK testWndProc(HWND hWnd, UINT Msg,
			     WPARAM wParam, LPARAM lParam)
{
	HDC hDC;

	switch(Msg)
	{
	case WM_CREATE:	
		return 0;

	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		return 0;

	case WM_PAINT:
		PAINTSTRUCT ps;
		hDC = BeginPaint(hWnd, &ps);
		draw(hDC);
		EndPaint(hWnd, &ps);
		return 0;

	case WM_LBUTTONDOWN:
		mouseDown(true, LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_RBUTTONDOWN:
		mouseDown(false, LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_MOUSEMOVE:
		mouseMove(LOWORD(lParam), HIWORD(lParam), hWnd);
		return 0;

	case WM_LBUTTONUP:
		mouseUp();
		return 0;

	case WM_RBUTTONUP:
		mouseUp();
		return 0;

	}

	return DefWindowProc(hWnd, Msg, wParam, lParam);
}

void makeWindow(HINSTANCE hInstance) {
	WNDCLASSEX WndClsEx;
	LPCTSTR ClsName = "easyPhysTest";
	LPCTSTR WndName = "Easy Physics Test";

	// Create the application window
	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc   = testWndProc;
	WndClsEx.cbClsExtra    = 0;
	WndClsEx.cbWndExtra    = 0;
	WndClsEx.hIcon         = 0;
	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	WndClsEx.lpszMenuName  = NULL;
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.hInstance     = hInstance;
	WndClsEx.hIconSm       = 0;

	// Register the application
	RegisterClassEx(&WndClsEx);

	// Create the window object
	HWND hWnd = CreateWindowEx(0,
		ClsName,
		WndName,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL);

	// Display the window to the user
	ShowWindow(hWnd, SW_SHOWNORMAL);// SW_SHOWNORMAL);
	UpdateWindow(hWnd);

	MSG Msg;
    while( GetMessage(&Msg, NULL, 0, 0) )
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
}